<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/8 0008
 * Time: 下午 12:00
 */

namespace app\sports_admin\model;


use think\Model;
use traits\model\SoftDelete;

class DeviceTemporaryNum extends Model
{
    use SoftDelete;
    protected $table = 'device_temporary_num';

    protected $pk = 'id';

    protected $autoWriteTimestamp = true;



    /**
     * 查询设备临时编号
     * @param $page 第几页
     * @param $rows 每页显示的条数
     * @param $number 设备编号
     */
    public static function numberList($page,$rows,$number,$batch,$version)
    {
        $rows = self::where(function ($query)use($number,$batch,$version){
                if($number){
                    $query->where('number',$number);
                }
                if($batch){
                    $query->where('batch',$batch);
                }
                if($version){
                    $query->where('version',$version);
                }
            })->page($page)->limit($rows)->order('id','desc')->select();
        $count = self::where(function ($query)use($number,$batch,$version){
            if($number){
                $query->where('number',$number);
            }
            if($batch){
                $query->where('batch',$batch);
            }
            if($version){
                $query->where('version',$version);
            }
        })->count();
        return json(['total'=>$count,'rows'=>$rows]);
    }
}